#! /usr/bin/env node

//对文件进行操作
const fs = require('fs');

const path = require("path");

const process=require("process")

const chalk = require("chalk");

//工程目录路径
const processPath = process.cwd()

//命令行参数
let argvName=process.argv[2]

//文件路径
const filePath = path.join(__dirname, './data');

//读取所有的文件名称
const textList = fs.readdirSync(filePath).map(item => item.replace(".txt", ""));

//随机数函数
const getRandomNum = (max, min) => Math.floor(Math.random() * (max - min + 1));

//当文件列表包含命令行参数时  就是命令行参数  否则给tangshi
argvName = textList.includes(argvName) ? argvName : "tangshi"

//截取key
const splitKey = argvName === "animals" ? "===============++++SEPERATOR++++====================" : "%";

//当前文件所有的文章
const curList = fs.readFileSync(path.join(filePath, argvName + ".txt"), "utf-8").split(splitKey);

//随机文章
const cur = curList[getRandomNum(curList.length, 0)];

//最终输出


console.log(chalk.rgb(getRandomNum(255,0),getRandomNum(255,0),getRandomNum(255,0))(cur));